#!/bin/bash
set -e  # Exit immediately if a command exits with a non-zero status.

DIR=$1
PKG=$2
VERSION=$3
RELEASE=$4
SRC_TAR=$5

SRPM="$PKG"-"$VERSION"-"$RELEASE".fc39.src.rpm

cd "$DIR"
rm "$PKG" -rf
mkdir -p "$PKG" && cd "$PKG"
git clone git@gitee.com:EdwardElric233/"$PKG".git
mkdir -p fedora/files && cd fedora/files
# wget https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/source/tree/Packages/q/$SRPM
wget https://kojipkgs.fedoraproject.org//packages/"$PKG"/"$VERSION"/"$RELEASE".fc39/src/"$SRPM"
rpm2cpio "$SRPM" | cpio -idvm
cp "$SRC_TAR" ../../"$PKG"
cd ../
git clone https://src.fedoraproject.org/rpms/"$PKG".git